home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / ship / powerup.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-29  |  3.5 KB  |  190 lines

  1. #include "game.h"
  2.  
  3. void powerup::draw()
  4. {
  5.     if (objmesh==0)
  6.         return;
  7.  
  8.     objmesh->color.vec(1,1,1);
  9.     if (life>500)
  10.         objmesh->color.w=1;
  11.     else
  12.     if (life<500)
  13.         objmesh->color.w=life/500.0f;
  14.     else if (life>source->life-500)
  15.             objmesh->color.w=(source->life-life)/500.0f;
  16.         else objmesh->color.w=0;
  17.  
  18.     if (l)
  19.         {
  20.         l->pos=pos;
  21.         if(l->s)
  22.             l->s->color.w=objmesh->color.w;
  23.         l->draw();
  24.         }    
  25.     glPushMatrix();
  26.     glTranslatef(pos.x,pos.y,pos.z);
  27.     glMultMatrixf((float *)&mat);
  28.     if (mode&1)
  29.         {
  30.         glDisable(GL_CULL_FACE);
  31.         glDepthMask(GL_FALSE);
  32.         glBlendFunc(GL_ONE, GL_ONE);
  33.         objmesh->draw();
  34.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  35.         glDepthMask(GL_TRUE);
  36.         glEnable(GL_CULL_FACE);
  37.         }
  38.     else 
  39.         objmesh->draw();
  40.     glPopMatrix();
  41. }
  42.  
  43. int powerup::step(int dt)
  44. {
  45.     life-=dt;
  46.     switch(directx->mpmode)
  47.     {
  48.     case FLYMP_SERVER:
  49.         {
  50.             static struct mp_data data;
  51.             data.flag=valuetype;
  52.             for( int i=1;i<directx->nplayers;i++ )
  53.             {
  54.                 if ((((bsp_object *)(directx->players[i].data))->pos-pos).length()<radius)
  55.                 {
  56.                     data.type=FLYMP_MSG_POWERUPGET;
  57.                     data.dpid=directx->players[i].dpid;
  58.                     directx->send_message((mp_msg *)&data,sizeof(mp_data));
  59.                     powerup_get((ship *)directx->players[i].data);
  60.                     life=-1;
  61.                     break;
  62.                 }
  63.             }
  64.             if (life<0)
  65.                 {
  66.                 flyengine->get_random_point(pos,radius);
  67.                 life=source->life;
  68.                 data.type=FLYMP_MSG_POWERUPMOVE;
  69.                 data.pos=pos;
  70.                 directx->send_message((mp_msg *)&data,sizeof(mp_data));
  71.                 }
  72.         }
  73.         break;
  74.     case FLYMP_CLIENT:
  75.         {
  76.             if (life<0) 
  77.                 life=0;
  78.             else
  79.                 {
  80.                 if (l && objmesh)
  81.                     {
  82.                     vector temp=l->color;
  83.                     l->color*=objmesh->color.w;
  84.                     l->pos=pos;
  85.                     l->step(dt);
  86.                     l->color=temp;
  87.                     }
  88.                 rotate(rot*(float)dt);
  89.                 }
  90.         }
  91.         break;
  92.     case FLYMP_NOMP:
  93.         {
  94.             vector v=flyengine->cam->pos-pos;
  95.             if ((v.x*v.x+v.y*v.y+v.z*v.z)<radius*radius)
  96.                 powerup_get((ship *)flyengine->cam);
  97.             if (life<0 && ((mode&2)==0))
  98.                 {
  99.                 flyengine->get_random_point(pos,radius);
  100.                 life=source->life;
  101.                 }
  102.             if (l && objmesh)
  103.                 {
  104.                 vector temp=l->color;
  105.                 l->color*=objmesh->color.w;
  106.                 l->pos=pos;
  107.                 l->step(dt);
  108.                 l->color=temp;
  109.                 }
  110.             rotate(rot*(float)dt);
  111.         }
  112.         break;
  113.     }
  114.     return 1;
  115. }
  116.  
  117. void powerup::powerup_get(ship *s)
  118. {
  119.     life=-1;
  120.  
  121.     if (valuetype>=0)
  122.         {
  123.         if (s!=flyengine->cam)
  124.             return;
  125.         if (valuetype<10 && s->g[valuetype])
  126.             s->g[valuetype]->firecount+=value;
  127.         }
  128.     else 
  129.         if (valuetype==-1)
  130.             {
  131.             s->shield+=(float)value;
  132.             if (s->shield>s->shield) 
  133.                 s->shield=s->shield;
  134.             }
  135.         else 
  136.         if (valuetype==-2 && s->flag3==0)
  137.             s->flag3=value|SHIP_FLAG3_INVISIBLE;
  138.         else 
  139.         if (valuetype==-3 && s->flag3==0)
  140.             s->flag3=value|SHIP_FLAG3_INVENSIBLE;
  141.     
  142.     if (l && s==flyengine->cam)
  143.         flyengine->filter+=l->color;
  144.     
  145.     if (sndget)
  146.         sndget->add_sound_clone(&pos,0);
  147. }
  148.  
  149. int powerup::get_custom_param_desc(int i,param_desc *pd)
  150. {
  151.     if (pd==0)
  152.         return 6;
  153.     else 
  154.     switch(i)
  155.     {
  156.         case 0:
  157.             pd->type='i';
  158.             pd->data=&valuetype;
  159.             strcpy(pd->name,"type");
  160.             break;
  161.         case 1:
  162.             pd->type='i';
  163.             pd->data=&value;
  164.             strcpy(pd->name,"value");
  165.             break;
  166.         case 2:
  167.             pd->type=TYPE_LIGHT;
  168.             pd->data=&l;
  169.             strcpy(pd->name,"light");
  170.             break;
  171.         case 3:
  172.             pd->type=TYPE_SOUND;
  173.             pd->data=&sndget;
  174.             strcpy(pd->name,"soundget");
  175.             break;
  176.         case 4:
  177.             pd->type='3';
  178.             pd->data=&objmesh;
  179.             strcpy(pd->name,"mesh");
  180.             break;
  181.         case 5:
  182.             pd->type='i';
  183.             pd->data=&mode;
  184.             strcpy(pd->name,"mode");
  185.             break;
  186.     }
  187.     return 0;
  188. }
  189.  
  190.